from rest_framework import serializers

from goods.models import SPU, Brand, GoodsCategory


# 获取spu表数据
class SPUSerializer(serializers.ModelSerializer):
    # 一级分类id
    category1_id = serializers.IntegerField()
    # 二级分类id
    category2_id = serializers.IntegerField()
    # 三级级分类id
    category3_id = serializers.IntegerField()
    # 关联的品牌id
    brand_id = serializers.IntegerField()
    # 关联的品牌，名称
    brand = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = SPU
        exclude = ('category1','category2','category3')

# 品牌表
class BrandSerializer(serializers.ModelSerializer):

    class Meta:
        model = Brand
        fields = ('id','name')

# 一级分类表
class GoodsCategorySerializer(serializers.ModelSerializer):

    class Meta:
        model = GoodsCategory
        fields = ('id','name')



